<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link rel="stylesheet" type="text/css" href="style_form.css" />
	<script language="javascript" src="error_valid.js"></script>
</head>

<body>
<?php
	// connect to the database
	include('./Connect_DB.php');
	include('stdlib.php');
	include('Model.php');
	
	 // check if the form has been submitted. If it has, start to process the form and save it to the database
	 if (isset($_POST['add']))
	 { 
		 // get form data, making sure it is valid
		 $id_unit = $_POST['id_unit'];
		 $name_faculty = $_POST['name_faculty'];
		 $name_subject = $_POST['name_subject'];
		 
		 // check to make sure both fields are entered
		if ($id_unit == '' || $name_faculty == '' || $name_subject == '')
		{
			//Dont submit
	 	}
		else
		{
		 //Check "Ma Don Vi" On the form with "maDonvi" is Primary key of "donvi" table within Database
			$row = Error_Add_Donvi($id_unit); //Call function from file Moodel.php
			if($row !=0)
			$error.= '"Mã Đơn Vị" bạn nhập trên Form đã tồn tại trong CSDL.'; 
			else
			{
				//Add data within Database
				Add_Donvi(); //Call function from file Moodel.php
				$message = 'Bạn đã thêm thông tin thành công'. ' Ban Click<a href="View_View_Donvi.php" > Here </a> Quay trở về trang View_View_Donvi.php';
				$id_unit = $name_faculty = $name_subject =''; 
				//echo " dfdfd".$name_faculty;				
			}
	 	}
	}
	
	echo '<h2><center>THÊM THÔNG TIN ĐƠN VỊ ÐÀO TẠO</center></h2>';
	echo '<br /><hr>';
	
	include('Form_Add_Donvi.php');
	
	echo '<center><b><font color="red">'.$message.'</font></b></center>';
	echo '<center><b><font color="red">'.$error.'</font></b></center>';	
?>
</body>
</html>
